package com.bjsc.mapper;

import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;

/**
 * @author create by VIC.Huang
 * @date 2018/2/8
 */
@Mapper
public interface UserMapper {
    @Update("update t_user_asset set frozen_asset = frozen_asset + #{money}" +
            " where user_id = #{userId} and frozen_asset >= ABS(#{money})")
    int updateUserFrozenAsset(@Param("userId") Long userId, @Param("money") BigDecimal money);

    @Select("select count(1) from t_user where id = #{userId}")
    int countUserById(Long userId);

    @Update("update t_user_asset set asset = asset + #{money} where user_id = #{userId}")
    int updateUserAsset(@Param("userId") Long userId, @Param("money") BigDecimal money);

    @Insert("insert into t_spend_record(user_id, type, money) values(#{userId},#{type},#{money})")
    int insertSpendRecord(@Param("userId") Long userId, @Param("type") String code, @Param("money") BigDecimal money);

    @Update("update t_user set disable = 1 where id = #{id}")
    int frozenUser(Long id);

    @Update("update t_user set disable = 0 where id = #{id}")
    int unfrozenUser(Long id);

    @Update("update t_user set disable = 1")
    int frozenAllUser();

    @Update("update t_user set system = #{system} where id = #{id}")
    int updateUserSystemFlag(@Param("id") Long id, @Param("system") String code);
}
